package com.neusoft.elm;

import com.neusoft.elm.po.Business;
import com.neusoft.elm.view.BusinessView;
import com.neusoft.elm.view.BusinessViewImpl;
import com.neusoft.elm.view.FoodView;
import com.neusoft.elm.view.FoodViewImpl;

import java.util.Scanner;

public class ElmBusinessEntry {

    public static void main(String[] args) {
        work();
    }
    public static void work(){

        Scanner sc = new Scanner(System.in);
        System.out.println("-------------------------------------------------------------");
        System.out.println("|\t\t\t\t\t 小源©的饿了么后台管理系统 \t\t\t\t\t|");
        System.out.println("-------------------------------------------------------------");

        BusinessView businessView = new BusinessViewImpl();

        //商家登录

        Business business = businessView.login();

        if(business != null){
            int menu = 0;
            while(menu != 5){
                System.out.println("-------------------------------------------------------------");
                System.out.println("|                欢迎使用小源©的饿了么后台管理系统                |");
                System.out.println("-------------------------------------------------------------");
                System.out.println("---------------------一级菜单(商家管理)-------------------------");
                System.out.println("---1.查看商家信息 2.修改商家信息 3.更改密码 4.所属商品管理 5.退出系统---");
                System.out.println("请输入您的选择: ");
                menu = sc.nextInt();
                switch(menu){
                    case 1:
                        businessView.showBusiness(business.getBusinessId());
                        break;
                    case 2:
                        businessView.editBusiness(business.getBusinessId());
                        break;
                    case 3:
                        businessView.updateBusinessByPassword(business.getBusinessId());
                        break;
                    case 4:
                        foodManager(business.getBusinessId());
                        break;
                    case 5:
                        System.out.println("---------<欢迎下次使用小源©的饿了么后台管理系统>---------");
                        break;
                    default:
                        System.out.println("!!!请输入正确的选项!!!");
                        }
                }

        }else{
            System.out.println("商家<编号>或<密码>输入错误!!!");
        }
    }

    private static void foodManager(int businessId){
        Scanner sc = new Scanner(System.in);

        FoodView foodView = new FoodViewImpl();

        int menu = 0;
        while(menu != 5){
            System.out.println("-------------------------------------------------------------");
            System.out.println("---------------------二级菜单(商家管理)-------------------------");
            System.out.println("----1.查看食品列表 2.新增食品 3.修改食品 4.删除食品 5.返回一级菜单----");
            System.out.println("请输入您的选择: ");
            menu = sc.nextInt();
            switch(menu){
                case 1:
                    foodView.showFoodList(businessId);
                    break;
                case 2:
                    foodView.saveFood(businessId);
                    break;
                case 3:
                    foodView.updateFood(businessId);
                    break;
                case 4:
                    foodView.removeFood(businessId);
                    break;
                case 5:
                    break;
                default:
                    System.out.println("!!!请输入正确的选项!!!");
            }
        }

    }
}
